//
// Created by admin on 2022/6/14.
// 198. 打家劫舍: https://leetcode.cn/problems/house-robber/
//
#include <vector>
using namespace std;

// 动态规划
class Rob {
public:
    int rob(vector<int>& nums) {
        if (nums.empty()) return 0;
        int len = nums.size();
        if (len == 1) return nums[0];
        vector<int> dp = vector<int>(len,0);
        dp[0] = nums[0];
        dp[1] = max(dp[0],nums[1]);

        for (int i = 2; i < len; ++i) {
            dp[i] = max(dp[i-2] + nums[i],dp[i-1]);
        }
        return dp[len-1];
    }
};

